package com.white.commonlib.utils;

/**
 * Created by yutf on 2017/6/28 0028.
 */

public class ColorUtils
{
    /***
     * 颜色渐变
     * @param fraction    比例因子0-1
     * @param startValue  起始颜色
     * @param endValue    目的颜色
     * @return
     */
    public static int evaluate(float fraction, int startValue, int endValue)
    {
        int startInt = startValue;
        int startA = (startInt >> 24) & 0xff;
        int startR = (startInt >> 16) & 0xff;
        int startG = (startInt >> 8) & 0xff;
        int startB = startInt & 0xff;

        int endInt = endValue;
        int endA = (endInt >> 24) & 0xff;
        int endR = (endInt >> 16) & 0xff;
        int endG = (endInt >> 8) & 0xff;
        int endB = endInt & 0xff;

        return (int)((startA + (int)(fraction * (endA - startA))) << 24) |
                (int)((startR + (int)(fraction * (endR - startR))) << 16) |
                (int)((startG + (int)(fraction * (endG - startG))) << 8) |
                (int)((startB + (int)(fraction * (endB - startB))));
    }
}
